-
Notifications
You must be signed in to change notification settings - Fork 0
🐛 Fix response unmarshalling issue when API has unknown fields #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
590bec1 to
a90b7b5
Compare
| } | ||
|
|
||
| func checkResponseMarshalling(ctx context.Context, apiErr error, resp *http.Response, result any) (err error) { | ||
| if apiErr != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is going to be its own function then you should check the statuscode too, before it was after something that did that so we knew it would be successful but here we don't and it could cause confusion if someone uses the function elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a private function though
| // At this point, the marshalling problem may be due to the present of unknown fields in the response due to an API extension. | ||
| // See https://github.com/OpenAPITools/openapi-generator/issues/21446 | ||
| var respB []byte | ||
| respB, err = safeio.ReadAll(ctx, resp.Body) | ||
| if err != nil { | ||
| return | ||
| } | ||
| _, err = marshmallow.Unmarshal(respB, result, marshmallow.WithSkipPopulateStruct(false), marshmallow.WithExcludeKnownFieldsFromMap(true)) | ||
| if err != nil { | ||
| err = commonerrors.WrapError(commonerrors.ErrMarshalling, err, "API call was successful but an error occurred during response marshalling") | ||
| return | ||
| } | ||
| } | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you do this I think the function needs to have a different name since it isn't just checking, it is also doing another unmarshal attempt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough
joshjennings98
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two comments but I think it will help a lot
Description
fix problem we see with clients when upgrading APIs
Test Coverage